const express = require('express');
const app = express();
app.use(express.json()); // 解析JSON请求体
app.use(express.urlencoded({ extended: true })); // 解析表单数据

// 获取查询参数
app.get('/search', (req, res) => {
  const { keyword, page = 1 } = req.query;
  res.json({ results: [`${keyword}结果1`, `${keyword}结果2`], currentPage: page });
});

// 处理POST请求体
app.post('/login', (req, res) => {
  const { username, password } = req.body;
  res.status(200).send(`欢迎 ${username}`);
});

// 路径参数示例
app.get('/products/:id', (req, res) => {
  res.send(`产品ID: ${req.params.id}`);
});

